#include "logging.hpp"
#include <string>
#include <vector>

namespace LOG
{

// enum class logType
// {
//     ERROR,
//     WARNING,
//     Running,
//     Normal,
//     Emergency,
// };
const char fresetcode[] = {"\033[39m"}; // 6
const char bresetcode[] = {"\033[49m"};
const char Black[] = "\x1b[30m";
const char Red[] = "\x1b[31m";
const char Green[] = "\x1b[32m";
const char Yellow[] = "\x1b[33m";
const char Blue[] = "\x1b[34m";
const char Magenta[] = "\x1b[35m";
const char Cyan[] = "\x1b[36m";
const char White[] = "\x1b[37m";
struct LogItem
{
    logType Type;
    std::string type;
    const char* color;
    std::string Tip;
    const char* resetcode{"\033[39m \033[49m"};
    std::string Content;
    std::string Result;
};
std::vector<LogItem> logging;
void Addlog(logType type, const char* loggingContent)
{
    for (const auto& it : logging)
    {
        if (it.Content.compare(loggingContent)) return;
    }
    LogItem item;
    item.Content = loggingContent;
    switch (type)
    {
    case logType::Error:
        item.Type = logType::Error;
        item.color = Red;
        item.Tip = "[ERROR] ";
        break;
    case logType::Warning:
        item.Type = logType::Warning;
        item.color = Yellow;
        item.Tip = ("[WARNING] ");
        break;
    case logType::Running:
        item.Type = logType::Running;
        item.color = Green;
        item.Tip = ("[Running] ");
        break;
    case logType::Normal:
        item.Type = logType::Normal;
        item.color = White;
        item.Tip = ("[Normal] ");
        break;
    case logType::Emergency:
        item.Type = logType::Emergency;
        item.color = Red;
        item.Tip = ("[EMERGENCY] ");
        break;
    }
    item.Result = item.color + item.Tip + item.resetcode + item.Content;
}

void ShowAll()
{
    printf("\033[1;1H");
    for (const auto& it : logging)
    {
        // printf("%s\n", it.Result.c_str());
    }
}

} // namespace LOG